<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.10/dist/vue.js"></script>
  <title>Document</title>
</head>

<body>
  <div id="app">
    <div id="div" v-if="showDiv">我是一个div</div>
    <button @click="getText">获取div中的内容</button>
  </div>
  <script>
    let vm = new Vue({
      el: "#app",
      data: {
        showDiv: false
      },
      methods: {
        // getText() {
        //   this.showDiv = true;
        //   let text = document.getElementById("div").innerHTML;
        //   console.log(text);
        // }
        getText() {
          this.showDiv = true;
          this.$nextTick(() => {
            let text = document.getElementById("div").innerHTML;
            console.log(text);
          })
        }
      },
    });
  </script>
</body>

</html>